package com.pbl6.back.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Arrays;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import xin.altitude.cms.common.entity.AjaxResult;
import com.pbl6.back.service.IExperienceService;
import java.util.List;
import com.pbl6.back.domain.Experience;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import xin.altitude.cms.common.entity.PageEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.pbl6.back.mapper.ExperienceMapper;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@RestController
@RequestMapping("/back/experience")
public class ExperienceController{
    @Autowired
    private IExperienceService experienceService;
    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity,Experience experience){
        return AjaxResult.success(experienceService.page(pageEntity.toPage(), Wrappers.lambdaQuery(experience)));
    }
    @GetMapping("/list")
    public AjaxResult list(Experience experience){

         LambdaQueryWrapper<Experience> experienceLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (experience.getDevicename() !=null&& !" ".equals(experience.getDevicename())) {
            experienceLambdaQueryWrapper.like(Experience::getDevicename,experience.getDevicename());
        }
        if (experience.getDevicefault() !=null&& !" ".equals(experience.getDevicefault())) {
            experienceLambdaQueryWrapper.like(Experience::getDevicefault, experience.getDevicefault());
        }
        return AjaxResult.success(experienceService.list(experienceLambdaQueryWrapper));

       /* return AjaxResult.success(experienceService.list(Wrappers.lambdaQuery(experience))); */
    }
    @PostMapping("/push")
    public AjaxResult add(@RequestBody Experience experience) {
        return AjaxResult.success(experienceService.save(experience));
    }
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Experience experience) {
        return AjaxResult.success(experienceService.updateById(experience));
    }
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(experienceService.removeByIds(Arrays.asList(ids)));
    }
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(experienceService.getById(id));
    }
}
